<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Jobtitle extends MY_Controller {

	//构造函数
	public function __construct()
	{
		parent::__construct();
		$this->load->model('dxdb_model','tit','job_title');
	}

   //获取所有的职称
	public function alltitle()
	{
		$data['titles'] = $this->tit->all();
		$this->load->view('title/alltitle',$data);
	}

	//职称添加
	public function title_add()
	{
		if(IS_POST)
		{
			$data = array();
			$data = array(
				'jt_title'    =>$this->input->post('jt_title'),
				'jt_sort'     =>$this->input->post('jt_sort')
		     );
			$flag = $this->tit->dx_insert($data);
			if($flag) $this->success('jobtitle/alltitle');
		}
		else
		{
			$this->load->view('title/title_add');
		}
	}

	//编辑
	public function title_edit()
	{
    	$eid = $this->uri->segment(3);
    	if(IS_POST)
    	{
    		$data = array();
			$data = array(
				'jt_title'    =>$this->input->post('jt_title'),
				'jt_sort'     =>$this->input->post('jt_sort')
		     );
    		$flag = $this->tit->dx_update($data,array('jt_id'=>$eid));
    		if($flag) $this->success('jobtitle/alltitle');
    	}
    	else
    	{
    		$data = $this->tit->one(array('jt_id'=>$eid));
    		$this->load->view('title/title_edit',$data);
    	}
	}

	//状态编辑
	public function title_status()
	{
		$id = intval($this->input->post('id'));
		$state = intval($this->input->post('state'));
		if($state == 1)
		{
		    $flag = $this->tit->dx_update(array('jt_status'=>0),array('jt_id'=>$id));$msg = '操作成功：信息屏蔽!';
		}
		else
		{
		    $flag = $this->tit->dx_update(array('jt_status'=>1),array('jt_id'=>$id));$msg = '操作成功：信息状态正常 :)';
		}
		if($flag) {$arr['status']  = 1;$arr['message']  = $msg;}else { $arr['status']  = 0;$arr['message']  = "操作失败 :(";} 
	    $this->ajax($arr); 
	}

	//状态删除
	public function title_del()
	{
		$id = intval($this->input->post('id'));
		//删除图片
		$flag = $this->tit->dx_delete(array('jt_id'=>$id));
		if($flag)
		{
		  $arr['status']  = 1; $arr['message']  = "删除信息成功 :)";
		}
		else
		{
		   $arr['status']  = 0; $arr['message']  = "操作失败 :(";         
		} 
		$this->ajax($arr); 
	}
}